package com.servlet;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "InputCodeServlet", value = "/InputCodeServlet")
public class InputCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//       设置验证码图片的高度宽度 字符数量和干扰线数量
        ValidateCode validateCode = new ValidateCode(200,30,4,20);
//        将正确的代码存储到session
        String code = validateCode.getCode();
        HttpSession session = request.getSession();
        session.setAttribute("code",code);

//        将图片输出到前端
        validateCode.write(response.getOutputStream());
    }
}
